//实现父子进程通信
const { fork } = require("child_process");

let childProcess = fork("07fork-child.js");

let index = 0;

let intervarId = setInterval(() => {
    childProcess.send("this is a message from parent process" + index);
    index++;
    if (index == 10) {
        clearInterval(intervarId);
    }
}, 1000);

childProcess.on("message", (msg) => {
    console.log(msg);
})